package org.goldenport.g3.sample

import org.goldenport.util.QSymbol
import org.goldenport.g3._
import org.goldenport.g3.adapters._
import org.goldenport.g3.messages.query._
import org.goldenport.g3.messages.entity._
import BookViewSpace._
import BookEntitySpace._

/**
 * @since   Aug. 31, 2010
 * @version Sep.  6, 2010
 * @author  ASAMI, Tomoharu
 */
class BookViewDriver(val uri: String) extends G3ViewDriver {
  def new_Agent(cmd: G3Command, ctx: G3AgentContext) = {
    QSymbol(cmd.uri) match {
      case VIEW_BOOK => {
        val driver = new BookEntityDriver()
        new BookViewDriverAgent(driver, ctx)
      }
    }
  }
}

class BookViewDriverAgent(driver: G3EntityDriver, context: G3AgentContext) extends G3EntityViewDriverAgent(driver, context) {
  val entityName: QSymbol = KIND_BOOK // primary entity name
  val result = RecordQuery(
//    EntityAll(entityName)(5),
    Entity(KIND_BOOK)(Id(Var('id)))(
      AllFields,
      IncludeEntity(KIND_PUBLISH, BackRef('book))(
        Field('id),
        Field('date)
      )
    )
  )
}

object BookViewSpace {
  val VIEW_BOOK = QSymbol('viewbook)
  val VIEW_AUTHOR = QSymbol('viewauthor)
  val VIEW_PUBLISHER = QSymbol('viewpublisher)
}
